package com.netease.calendar;

import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarView;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private CalendarView mCalendarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private static final String TAG = "MainActivity";
    private void initView() {
        mCalendarView = (CalendarView) findViewById(R.id.calendarView);
        Map<String, Calendar> map=new HashMap<>();
        map.put(getSchemeCalendar(2021, 10, 22, 0xFF40db25, "").toString(),
                getSchemeCalendar(2021,10, 22, 0xFF40db25, ""));
        map.put(getSchemeCalendar(2021, 10, 21, 0xFF40db25, "").toString(),
                getSchemeCalendar(2021,10, 21, 0xFF40db25, ""));
        map.put(getSchemeCalendar(2021, 10, 20, 0xFF40db25, "").toString(),
                getSchemeCalendar(2021,10, 20, 0xFF40db25, ""));
        mCalendarView.setSchemeDate(map);



        mCalendarView.setOnCalendarSelectListener(new CalendarView.OnCalendarSelectListener() {
            @Override
            public void onCalendarOutOfRange(Calendar calendar) {

            }

            @Override
            public void onCalendarSelect(Calendar calendar, boolean isClick) {
                Log.d(TAG, "onCalendarSelect: "+calendar.getYear()+calendar.getMonth()+calendar.getDay());
            }
        });
    }
    private Calendar getSchemeCalendar(int year, int month, int day, int color, String text) {
        Calendar calendar = new Calendar();
        calendar.setYear(year);
        calendar.setMonth(month);
        calendar.setDay(day);
        calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
        calendar.setScheme(text);
        return calendar;
    }
}